/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.session;

import com.thienloc.omap.entity.ServiceSuggestion;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
@Stateless
public class ServiceSuggestionFacade extends AbstractFacade<ServiceSuggestion> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @PersistenceContext(unitName = "omapPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ServiceSuggestionFacade() {
        super(ServiceSuggestion.class);
    }

    public List<String> findAllAlikeFullCommand(String fullCommand) throws Exception {
        try {
            TypedQuery<String> q = em.createNamedQuery("ServiceSuggestion.findAllAlikeFullCommand", String.class);
            q.setParameter("fullCommand", fullCommand + "%");
            return q.getResultList();
        } catch (NoResultException ex) {
            return new ArrayList<String>(0);
        } catch (Exception ex) {
            logger.error("", ex);
            return new ArrayList<String>(0);
        }
    }
    
    public List<ServiceSuggestion> findByFullCommand(String fullCommand) throws Exception {
        try {
            TypedQuery<ServiceSuggestion> q = em.createNamedQuery("ServiceSuggestion.findByFullCommand", ServiceSuggestion.class);
            q.setParameter("fullCommand", fullCommand);
            return q.getResultList();
        } catch (NoResultException ex) {
            return new ArrayList<ServiceSuggestion>(0);
        } catch (Exception ex) {
            logger.error("", ex);
            return new ArrayList<ServiceSuggestion>(0);
        }
    }
}
